<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let p1 = new Promise((resolve, reject) => {
      resolve(1)
    })
    let p2 = new Promise((resolve, reject) => {
      resolve(2)
    })
    function f1() {
      return p1
    }
    function f2() {
      return p2
    }
    let arr = [1, 2]
    async function fun1() {
      // 能卡住
      await Promise.all(arr.map(async item => {
        let _ = await f1()
        console.log(item)
        console.log(_)
      }));

      // 能卡住
      // await arr.reduce(async (pre,next) => {
      //   let _ = await f1()
      //   console.log(next)
      //   console.log(_)
      //   return pre
      // },{});

      // 卡不住
      // await arr.forEach(async item => {
      //   let _ = await f1()
      //   console.log(item)
      //   console.log(_)
      // });

      // 只有forEach卡不住
      console.log('-------------------------')
    }
    async function fun2() {
      for (let i = 0; i < arr.length; i++) {
        let _ = await f2()
        console.log(arr[i])
        console.log(_)
      }
      console.log('/////////////////////////')
    }
    fun1()
    fun2()
    console.log('end')
  </script>
</body>

</html>